package FlowerMgr;

import java.util.Scanner;

public class FlowerMgr {
    String[][] ARR = new String[10][7];
    Scanner INPUT = new Scanner(System.in);

    //定义初始化方法
    public void inital() {
        String[] eleArr1 = {"1001", "金色海岸-香槟玫瑰", "10", "318.0", "2016-12-12", "王二昵", " "};
        String[] eleArr2 = {"1002", "初心永不变-白玫瑰", "99", "538.0", "2016-12-20", "张欣雨", " "};
        String[] eleArr3 = {"1003", "梦里花开-紫色桔梗", "40", "148.0", "2016-12-24", "王二昵", "眼波如水，映出窗外繁星点点"};
        String[] eleArr4 = {"1004", "心花怒放-粉香百合", "120", "188.0", "2016-12-26", "王二昵", "内层银灰色厚棉袄，外层深蓝色条纹纸，银灰色缎带"};
        String[] eleArr5 = {"1005", "致青春-无声的爱", "1000", "219.0", "2016-12-18", "张欣雨", "我爱你，胜过爱爱情，更胜过爱自己！"};

        ARR[0] = eleArr1;
        ARR[1] = eleArr2;
        ARR[2] = eleArr3;
        ARR[3] = eleArr4;
        ARR[4] = eleArr5;
    }

    //主菜单，用于完成功能面板的展示及功能选择
    public void mainMenu() {
        while (true) {
            System.out.println("===============欢迎光临七彩鲜花销售系统===============");
            System.out.println("1.查询销售订单");
            System.out.println("2.修改销售订单");
            System.out.println("3.删除销售订单");
            System.out.println("4.系统退出");
            System.out.println("==================================================");
            //键盘录入用户的选择
            System.out.print("请输入您要进行的操作：");
            int choice = INPUT.nextInt();
            switch (choice) {
                case 1:
                    //调用查询方法
                    searchAll();
                    break;
                case 2:
                    //调用修改订单方法
                    updateSale();
                    break;
                case 3:
                    //调用删除订单方法
                    deleteSale();
                    break;
                default:
                    //系统退出
                    System.out.println("系统退出，谢谢你的使用!");
                    System.exit(0);
            }
        }
    }

    //定义查询方法
    public void searchAll() {
        //打印表头
        System.out.println("编号\t鲜花名称\t销售数量\t价格\t销售日期\t销售员\t备注");
        //遍历打印二维数组
        for (int i = 0; i < ARR.length; i++) {
            String[] eleArr = ARR[i];
            if (eleArr[0] != null) {
                for (String s : eleArr) {
                    System.out.print(s + "\t");
                }
                System.out.println();
            }
        }
        System.out.println();
    }

    //定义修改订单方法
    private void updateSale() {
        System.out.println("请输入销售编号:");
        int index = -1;
        //接受键盘录入的销售编号
        String id = INPUT.next();
        for (int i = 0; i < ARR.length; i++) {
            if (id != null && id.equals(ARR[i][0])) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            System.out.println("对不起，您要修改的订单号不存在！");
            return;
        }
        //程序走到此处 说明订单号存在，且不为null
        System.out.println("您要修改的订单详细信息如下:");
        //遍历数组
        for (int i = 0; i < ARR.length; i++) {
            String[] eleArr = ARR[i];
            //打印编号为id的一维数组元素
            if (id.equals(ARR[i][0])) {
                for (String s : eleArr) {
                    System.out.print(s + "\t");
                }
            }
        }
        //换行
        System.out.println();

        System.out.println("请输入修改后的鲜花名称:");
        String name = INPUT.next();
        System.out.println("请输入修改后的销售数量:");
        String number = INPUT.next();
        System.out.println("请输入修改后的鲜花价格:");
        String price = INPUT.next();
        System.out.println("请输入修改后的销售日期:(yyyy-MM-dd)");
        String date = INPUT.next();
        System.out.println("请输入修改后的销售员:");
        String employ = INPUT.next();
        System.out.println("请输入修改后的备注:");
        String biz = INPUT.next();

        System.out.println("您确定要修改吗?(y/n)");
        //将"y"和输入的数据比较
        if ("y".equals(INPUT.next())) {
            ARR[index][1] = name;
            ARR[index][2] = number;
            ARR[index][3] = price;
            ARR[index][4] = date;
            ARR[index][5] = employ;
            ARR[index][6] = biz;
        } else {
            System.out.println("取消修改");
            return;
        }
        System.out.println("修改成功");
        //调用查询方法
        searchAll();
    }

    //定义删除订单方法
    private void deleteSale() {
        int index = -1;
        System.out.println("请输入要删除的订单编号:");
        String id = INPUT.next();
        for (int i = 0; i < ARR.length; i++) {
            if (id != null && id.equals(ARR[i][0])) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            System.out.println("对不起，没有您要删除的订单编号");
            return;
        }
        //程序走到此处 说明订单号存在，且不为null
        System.out.println("您要删除的订单详细信息如下:");
        for (int i = 0; i < ARR.length; i++) {
            String[] strs = ARR[i];
            if (id.equals(ARR[i][0])) {
                for (String str : strs) {
                    System.out.print(str + "\t");
                }
            }
        }
        System.out.println();
        System.out.println("您确定要删除吗?(y/n)");
        //将"y"和输入的数据比较
        if ("y".equals(INPUT.next())) {
            for (int i = index + 1; i < ARR.length; i++) {
                //将index后面的元素整体向前平移一个位置
                ARR[index] = ARR[i];
            }
        }
        System.out.println("删除成功！");
        searchAll();
    }
}
